package io.zhiller.simpletemplate

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import io.zhiller.simpletemplate.plugin.update.UpdateManager
import io.zhiller.simpletemplate.ui.theme.AppTheme

class MainActivity : ComponentActivity() {
  
  
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    enableEdgeToEdge()
    setContent {
      AppTheme(darkTheme = isSystemInDarkTheme()) {
        Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
          Box(modifier = Modifier.windowInsetsPadding(WindowInsets.statusBars)) {
            UpdateManager.UpdateComp(this@MainActivity)
          }
        }
      }
    }
  }
}

//@Composable
//fun DownloadCard(
//  context: Context, downloadFileInfo: DownloadFileInfo, onFinished: () -> Unit = {}
//) {
//  var downloadFileStatus by remember { mutableStateOf(DownloadFileStatus.INITIAL as DownloadFileStatus) }
//  var currentProgress by remember { mutableIntStateOf(0) }
//  var alreadyDownloadSize by remember { mutableLongStateOf(0L) }
//  var status by remember { mutableStateOf("Download") }
//  var enableButton by remember { mutableStateOf(true) }
//  val coroutineScope = rememberCoroutineScope()
//  Column(
//    modifier = Modifier.padding(12.dp),
//  ) {
//    Row(
//      verticalAlignment = Alignment.CenterVertically
//    ) {
//      Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier
//        .clickable {
//          if (enableButton) {
//            enableButton = false
//            coroutineScope.launch(Dispatchers.IO) {
//              runCatching {
//                FileApis
//                  .downloadFile(
//                    context = context,
//                    downloadUrl = downloadFileInfo.downloadUrl,
//                    saveFile = downloadFileInfo.saveFile,
//                  ) { process, alreadyDownloadedSize ->
//                    alreadyDownloadSize = alreadyDownloadedSize
//                    currentProgress = process
//                  }
//                  .collect { infos ->
//                    downloadFileStatus = infos
//                    status = when (infos) {
//                      is DownloadFileStatus.COMPLETED -> "Completed"
//                      is DownloadFileStatus.INITIAL -> "UnStart"
//                      is DownloadFileStatus.PROGRESS -> "Downloading"
//                      is DownloadFileStatus.FAILED -> "Failed"
//                    }
//                    if (infos is DownloadFileStatus.COMPLETED) onFinished()
//                  }
//              }.onFailure {
//                it.printStackTrace()
//                return@launch
//              }
//              enableButton = true
//            }
//          }
//        }
//        .clip(
//          RoundedCornerShape(8.dp)
//        )
//        .background(inversePrimaryLight)
//        .padding(12.dp)
//        .animateContentSize()) {
//        Icon(
//          imageVector = Icons.Default.Downloading,
//          contentDescription = null,
//          modifier = Modifier.padding(end = 12.dp),
//        )
//        Text(
//          text = status,
//          modifier = Modifier.align(Alignment.CenterVertically),
//        )
//      }
//
//      AnimatedVisibility(visible = !enableButton) {
//        Text(
//          modifier = Modifier
//            .animateContentSize()
//            .padding(start = 12.dp),
//          text = "${FileUtils.convertFileSize(alreadyDownloadSize)} / ${currentProgress}%"
//        )
//      }
//    }
//    Spacer(modifier = Modifier.padding(top = 8.dp))
//    LinearProgressIndicator(
//      progress = { currentProgress / 100f },
//      modifier = Modifier
//        .padding(top = 12.dp)
//        .fillMaxWidth(),
//    )
//    Spacer(modifier = Modifier.padding(top = 8.dp))
//  }
//}

